//
//  SCMaintUploadHeaderCCell.m
//  Shuaiche
//
//  Created by yujunyang on 2021/4/29.
//  Copyright © 2021 ShuaiChe. All rights reserved.
//

#import "SCMaintUploadPdfHeaderView.h"
#import <Masonry/Masonry.h>

@implementation SCMaintUploaldTipView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = SCColor(0xFEFCEB);
        UIImageView *imageView = [UIImageView new];
        imageView.image = [UIImage imageNamed:@"icon_time_tip"];
        [self addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.size.mas_equalTo(CGSizeMake(14, 14));
            make.centerY.equalTo(self);
        }];
        
        UILabel *tip = [UILabel new];
        tip.text = @"请选择一种形式上传，建议上传PDF完整报告。";
        tip.font = [UIFont systemFontOfSize:12];
        tip.textColor = SCColor(0xF96A0E);
        
        [self addSubview:tip];
        [tip mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(40);
            make.centerY.equalTo(self);
        }];
    }
    return self;
}

@end

@interface SCMaintUploadPdfHeaderView()

@property (nonatomic, strong) UIButton *btn;
@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *deleteBtn;

@end


@implementation SCMaintUploadPdfHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UILabel *title = [UILabel new];
        title.text = @"上传PDF文件";
        title.font = [UIFont systemFontOfSize:14];
        [self addSubview:title];
        [title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.height.mas_equalTo(56);
            make.top.mas_equalTo(0);
        }];
        
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn.frame = CGRectMake(0, 0, kSCScreenWidth-38*2, 120);
        _btn.backgroundColor = SCColor(0xFFFCF1);
        _btn.adjustsImageWhenHighlighted = NO;
        [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_btn];
        [_btn setBackgroundImage:[UIImage imageNamed:@"report_bg"] forState:UIControlStateNormal];
        [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(38);
            make.height.mas_equalTo(120);
            make.top.equalTo(title.mas_bottom);
            make.right.mas_equalTo(-38);
            make.bottom.mas_equalTo(0);
        }];

        _iconView = [UIImageView new];
        _iconView.image = [UIImage imageNamed:@"report_upload"];
        [_btn addSubview:_iconView];
        [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(15);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(48, 48));
        }];

        _titleLabel = [UILabel new];
        _titleLabel.text = @"点击上传文件";
        _titleLabel.font = SC_FONT(12);
        _titleLabel.textColor = SC_TextBlack_Secondary;
        [_btn addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_iconView.mas_bottom).offset(10);
            make.centerX.equalTo(self);
        }];
        
        _deleteBtn = [UIButton new];
        [_deleteBtn setTitle:@"仅支持PDF文件" forState:UIControlStateNormal];
        _deleteBtn.titleLabel.font = SC_FONT(10);
        [_deleteBtn setTitleColor:SC_TextBlack_Third forState:UIControlStateNormal];
        [_deleteBtn addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];
        [_btn addSubview:_deleteBtn];
        [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLabel.mas_bottom).offset(5);
            make.centerX.equalTo(self);
        }];
        
    }
    return self;
}

- (void)setPdfModel:(SCReportPdfModel *)pdfModel{
    
    _pdfModel = pdfModel;
    if (_pdfModel.showFile) {
        _iconView.image = [UIImage imageNamed:@"report_pdf"];
        if (pdfModel.fileName.length > 0) {
            _titleLabel.text = pdfModel.fileName;
        }else{
            NSURL *url = [NSURL URLWithString:pdfModel.reportPdf];
            _titleLabel.text = [url lastPathComponent];
        }
        [_deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
    }else{
        _iconView.image = [UIImage imageNamed:@"report_upload"];
        _titleLabel.text = @"点击上传文件";
        [_deleteBtn setTitle:@"仅支持PDF文件" forState:UIControlStateNormal];
    }
}

- (void)btnClick{
    //预览
    if (_pdfModel.showFile) {
        if (self.previewBlock) {
            self.previewBlock();
        }
    }else{//打开文件库
        if (self.clickBlock) {
            self.clickBlock();
        }
    }
}

- (void)deleteClick{
    
    if (_pdfModel.showFile) {
        if (self.deleteBlock) {
            self.deleteBlock();
        }
    }
    
}
@end


@implementation SCMaintUploadUrlHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _titleLabel = [UILabel new];
        _titleLabel.text = @"第三方链接";
        _titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.mas_equalTo(15);
        }];
        
        UIView *tfView = [UIView new];
        tfView.backgroundColor = SCColor(0xF7F8F8);
        tfView.layer.cornerRadius = 6.f;
        tfView.layer.masksToBounds = YES;
        [self addSubview:tfView];
        [tfView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(35);
            make.edges.equalTo(self).insets(UIEdgeInsetsMake(45, 15, 0, 35));
        }];
        
        _textFiled = [UITextField new];
        _textFiled.placeholder = @"请输入车辆检测报告链接";
        _textFiled.font = SC_FONT(14);
        [_textFiled addTarget:self action:@selector(textValueDidChanged:) forControlEvents:UIControlEventEditingChanged];
        [tfView addSubview:_textFiled];
        [_textFiled mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(tfView).insets(UIEdgeInsetsMake(0, 10, 0, 10));
        }];
       
    }
    return self;
}

- (void)textValueDidChanged:(UITextField *)textField {
    if (_textChangeBlock) {
        _textChangeBlock(textField.text);
    }
}

@end
